package lettuce;

import com.lambdaworks.redis.RedisClient;
import com.lambdaworks.redis.RedisFuture;
import com.lambdaworks.redis.RedisURI;
import com.lambdaworks.redis.api.StatefulRedisConnection;
import com.lambdaworks.redis.api.async.RedisAsyncCommands;
import com.lambdaworks.redis.api.sync.RedisCommands;

import java.util.concurrent.ExecutionException;
import java.util.concurrent.Future;

public class Demo1 {
    public static void main(String[] args) throws ExecutionException, InterruptedException {
        RedisURI uri = RedisURI.create("redis://192.168.10.100:6379");
        uri.setPassword("Bocon123456*");
        RedisClient client = RedisClient.create(uri);
        StatefulRedisConnection<String, String> connect = client.connect();


        //同步
        RedisCommands<String, String> commands = connect.sync();
        String name = commands.get("name");
        System.out.println(name);

        //异步
        RedisAsyncCommands<String, String> asyncCommands = connect.async();
        RedisFuture<String> nameReslut = asyncCommands.get("name");
        System.out.println(nameReslut.get());

        RedisFuture<String> sexResult = asyncCommands.set("sex", "1");
        RedisFuture<String> mobileResult = asyncCommands.set("mobile", "15817038288");

        System.out.println(sexResult.get()+", "+mobileResult.get());
    }
}
